package com.webserver.core;

import com.webserver.http.HttpRequest;

import java.io.IOException;
import java.io.InputStream;
import java.net.Socket;
import java.util.HashMap;
import java.util.Map;

/**
 * 负责与指定客户端进行HTTP交互
 * HTTP协议要求与客户端的交互规则采取一问一答的方式。因此，处理客户端交互以3步形式完成:
 * 1:解析请求(一问)
 * 2:处理请求
 * 3:发送响应(一答)
 */
public class ClientHandler implements Runnable {
    private Socket socket;

    public ClientHandler(Socket socket) {
        this.socket = socket;
    }

    @Override
    public void run() {
        try {
            /**
             * 获取IP命令
             * Windows:ipconfig
             * Mac:ifconfig
             */
            //1.解析请求
            HttpRequest request = new HttpRequest(socket);

            //2.处理请求

            //3.发送求情

        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            //处理完毕毕业后断开连接
            try {
                socket.close();
            } catch (IOException e) {
                e.printStackTrace();
            }

        }
    }

}